package gameDisplayer;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;

import java.util.List;
import javax.swing.JComponent;
import gameManager.Interactable;



/**
 * This class serves to create the actual game to be displayed. The
 * main paint function resides here and illustrates the background and
 * all the interactables on the canvas.
 * @author Kannan, Xi Du
 *
 */
public class Game extends JComponent {

/**
     */
    private static final long serialVersionUID = 1L;
/**
 * The list of all the objects (things which are interactable) in the game.
 */
private List<Interactable> myInteractableCharacters;
/**
 * A background image, uploaded by the game developer, to serve as a backdrop
 * for the game while it is running.
 */
private Image myBackGroundImage;

    /**
     * The constructor for this Game Class, taking in the list of
     * InteractableCharacters, built by the GameManager class.
     * @param interactableCharacters
     */
    public Game(List<Interactable> interactableCharacters){
    myInteractableCharacters = interactableCharacters;
    }
    /**
     * The main/primary paint function for the program, actually illustrates
     * the background and all the objects (interactables) in the game.
     * @param pen The graphics/drawing tool to be used in drawing a
     * visualization
     * @param dim The dimensions of the window (width, height)
     */
    public void paintComponent(Graphics2D pen, Dimension dim) {
        drawBackground(pen, myBackGroundImage);
        for (Interactable i:myInteractableCharacters) {
       pen.drawImage(i.getObjectImage(), i.getCenter().x,
                     i.getCenter().y, null);
        }
    }
    /**
     * Sets the BackgroundImage..
     * @param image The image to be served as the background.
     */
    public void setmyBackGroundImage(Image image){
        myBackGroundImage = image;
    }
    /**
     * Draws The Background Image to the canvas.
     * @param pen The graphics/drawing tool to be used in drawing a
     * visualization
     * @param myImage The Image to serve as teh background
     */
    public void drawBackground(Graphics2D pen, Image myImage){
        pen.drawImage(myImage, 0, 0, null);

    }

}

